﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LY.Manage.Model;
using System.IO;

namespace LY.Manage.WebApp.Controllers
{
    public class ActionInfoController : Controller
    {
        //
        // GET: /ActionInfo/

        IBLL.IActionInfoService ActionInfoService { get; set; }

        public ActionResult Index()
        {
            return View();
        }

        #region 获取权限信息
        public ActionResult GetActionInfoList()
        {
            //如果异常记录日志抛出去
            int pageIndex = Request["page"] != null ? int.Parse(Request["page"]) : 1;
            int pageSize = Request["rows"] != null ? int.Parse(Request["rows"]) : 5;
            int totalCount = 0;
            var actionInfoList=  ActionInfoService.LoadPageEntities<int>( pageIndex,pageSize, 
                out totalCount,
                u => u.DelFlag == (short)Model.EnumType.DeleteEnumType.Normarl
                
                ,u=>u.ID,true);
            var temp = from a in actionInfoList
                       select new
                       {
                           ID=a.ID,
                           ActionInfoName=a.ActionInfoName,
                           Sort=a.Sort,
                           Remark=a.Remark,
                           Url=a.Url,
                           HttpMethod=a.HttpMethod,
                           ActionTypeEnum=a.ActionTypeEnum,
                           SubTime=a.SubTime
                       };
            return Json(new {rows=temp,total=totalCount},JsonRequestBehavior.AllowGet );



        } 
        #endregion


        #region 添加权限信息
        public ActionResult ShowAddInfo()
        {


            return View();
        }
        #endregion



        #region FileUpLoad
        public ActionResult FileUpLoad()
        {
            HttpPostedFileBase file = Request.Files["fileIconUp"];
            string fileName = Path.GetFileName(file.FileName);
            string fileExt = Path.GetExtension(fileName);
            if (fileExt == ".jpg")
            {
                string dir = "/ImageIcon/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/";
                Directory.CreateDirectory(Path.GetDirectoryName(Request.MapPath(dir)));
                string newfileName = Guid.NewGuid().ToString();
                string fullDir = dir + newfileName + fileExt;
                file.SaveAs(Request.MapPath(fullDir));
                //自己加上图片的缩略图
                return Content("ok:" + fullDir);
            }
            else
            {
                return Content("no:文件类型错误!!");
            }
        }
        #endregion

    }
}
